<template>
  <div class="hello">
    <h1>{{ msg }}</h1>
    <button @click="num += 1">计数</button>
    <span>{{ num }}</span>
  </div>
</template>

<script>
export default {
  name: "HelloWorld",
  // props: {
  //   msg: String,
  // },
  // props: ["msg"],
  props: {
    msg: {
      type: String,
      default: "Hi",
    },
  },
  data() {
    return {
      num: 0,
    };
  },
  beforeCreate() {
    console.log("HelloWorld beforeCreate");
  },
  created() {
    console.log("HelloWorld created");
  },
  beforeMount() {
    console.log("HelloWorld beforeMount");
  },
  mounted() {
    console.log("HelloWorld mounted");

    this.timer = setInterval(() => {
      console.log("---- setInterval ----");
    }, 1000);
  },
  beforeUpdate() {
    console.log("HelloWorld beforeUpdate");
  },
  updated() {
    console.log("HelloWorld updated");
  },
  beforeDestroy() {
    console.log("HelloWorld beforeDestroy");
    clearInterval(this.timer);
  },
  destroyed() {
    console.log("HelloWorld destroyed");
  },
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="scss">
.hello {
  border: 1px dashed #333;
  padding: 20px;
}
a {
  color: #42b983;
}
</style>
